package com.malachi.plugin.validateattr;

import com.malachi.plugin.validateattr.annotation.AttrValidate;
import com.malachi.plugin.validateattr.service.impl.BillBelongTimeValidateAdapter;

import java.text.ParseException;

public class Main {
    public static void main(String[] args) throws ParseException {
        Demo demo = new Demo();
        demo.name = "malachi";
        demo.age = 18;
        demo.sex = "0";
//        demo.country = "中国";
        demo.testTime = "2026-01-01 01:10:10";
        String execute = new ValidateAttrUtil<Demo>().execute(Demo.class, demo);
        System.out.println(execute);

    }

    public static class Demo{
        @AttrValidate(name = "姓名", type = AttrValidate.TypeEnum.STRING, required = true, maxLength = 10)
        private String name;
        @AttrValidate(name = "年龄", type = AttrValidate.TypeEnum.INTEGER, required = true, positive = true)
        private Integer age;
        @AttrValidate(name = "性别", type = AttrValidate.TypeEnum.ENUM, required = true, classPath = "com.malachi.plugin.validateattr.Main$Sex")
        private String sex;
        @AttrValidate( name = "国家", type = AttrValidate.TypeEnum.DICT, required = false, dictType = "country")
        private String country;
        @AttrValidate(name = "测试时间", type = AttrValidate.TypeEnum.DATE, required = true, dateValidateAdapter = BillBelongTimeValidateAdapter.class)
        private String testTime;

        public String getName() {
            return name;
        }

        public Demo setName(String name) {
            this.name = name;
            return this;
        }

        public Integer getAge() {
            return age;
        }

        public Demo setAge(Integer age) {
            this.age = age;
            return this;
        }

        public String getSex() {
            return sex;
        }

        public Demo setSex(String sex) {
            this.sex = sex;
            return this;
        }

        public String getCountry() {
            return country;
        }

        public Demo setCountry(String country) {
            this.country = country;
            return this;
        }

        public String  getTestTime() {
            return testTime;
        }

        public Demo setTestTime(String testTime) {
            this.testTime = testTime;
            return this;
        }
    }

    public enum Sex {
        MALE(0, "男"), FEMALE(1, "女");
        private final Integer value;
        private final String name;
        Sex(Integer value, String name) {
            this.value = value;
            this.name = name;
        }


        public Integer getValue() {
            return value;
        }

        public String getName() {
            return name;
        }
    }
}